package com.lingyue.commons.constants;

import java.util.ArrayList;
import java.util.List;

/**
 * 选项枚举 1-Y 0-N
 *
 * @author deep.wu
 * @version 1.0 on 2020/1/6
 */
public class CommonOption {

    public static final String OPTION_0 = "0";
    public static final String OPTION_1 = "1";
    public static final String OPTION_2 = "2";
    public static final String OPTION_10 = "10";

    public static final String OPTION_Y = "Y";
    public static final String OPTION_N = "N";

    public static final String OPTION_ALL = "all";
    public static final String OPTION_DEFAULT = "";

    public static final String[] CASCADE = {"B9999020","B9999021","B9999022"};

    public static List<String> getOption() {
        List<String> resultList = new ArrayList<>();
        resultList.add(OPTION_N);
        resultList.add(OPTION_Y);
        return resultList;
    }

    public static String convertToStr(Object option) {
        if (option == null) {
            return null;
        }
        switch (option.toString().toUpperCase()) {
            case OPTION_0:
            case OPTION_N:
                return OPTION_N;
            case OPTION_1:
            case OPTION_Y:
                return OPTION_Y;
            default:
                return OPTION_DEFAULT;
        }
    }

    public enum YesOrNoEnum {
        /**
         * enum
         */
        Y(OPTION_Y, "是"),
        N(OPTION_N, "否"),
        UNKNOWN(OPTION_DEFAULT, "未知的选项");

        String code;
        String text;

        YesOrNoEnum(String code, String text) {
            this.code = code;
            this.text = text;
        }

        public String code() {
            return this.code;
        }

        public String text() {
            return this.text;
        }

        public static String getText(String code) {
            for (YesOrNoEnum item : YesOrNoEnum.values()) {
                if (item.code().equals(code)) {
                    return item.text();
                }
            }
            return OPTION_DEFAULT;
        }
    }
}